home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++,comp.lang.misc
- Path: news.clark.net!bms88!stuart
- From: stuart@bmsi.com (Stuart D. Gathman)
- Subject: Re: Languages and architecture Was: Re: Access carry flag from C
- Organization: Business Management Systems, Inc., Fairfax, VA
- Date: Fri, 1 Mar 1996 20:29:04 GMT
- Message-ID: <1996Mar1.202904.20064@bmsi.com>
- References: <Dn1C9z.DGv.0.net@indra.com> <3132f352.32867731@netline-fddi.jpl.nasa.gov> <4h1mcb$178u@b.stat.purdue.edu>
-
- In article <4h1mcb$178u@b.stat.purdue.edu> hrubin@b.stat.purdue.edu (Herman Rubin) writes:
- >In article <3132f352.32867731@netline-fddi.jpl.nasa.gov>,
- >Kevin Quitt <kdq@emoryi.jpl.nasa.gov> wrote:
- >>On Mon, 19 Feb 1996 18:20:22 GMT, sullivan@indra.com (Steve Sullivan) wrote:
- >
- >>>Is it possible to determine if a fixed point overflow has
- >>>occurred from within C?
- >
- >>No, it's not, because as far as C is concerned, there doesn't have to be a
- >>carry bit. Once overflow has occurred, you're into undefined behaviour.
- >
- >This is a problem with C and just about every other language, which
- >impacts adversely the architecture of machines.
- >
- >The language designers typically remove much of what a knowledgeable
- >user will want to use from the language, because their own knowledge
- >is lacking in that area. Then the designers of the arithmetic units
- >of the machines drop that property, because the languages do not
- >have it.
- >
- >And now we have computers on which many cheap instructions and
- >properties are not present. We cannot detect overflow, so we
- >are forced to either use many times the number of instructions,
- >or find some other clumsy way areound the problem. We cannot
- >do decent precise fixed point arithmetic, so the time for
- >multiple precision arithmetic, fixed or floating, is increased
- >by a substantial factor. Even the floating point unit has been
- >restricted so that, for example, doubling the machine precision
- >is a major undertaking.
- >
- >We can always simulate any computer on any other. Hardware
- >deficiencies are not handled efficiently by software.
-
- I program in C for Wintel, 68k, 88k, and PowerPC. The latter three
- (and I believe the former) all have cheap hardware overflow detection.
- While the C standard does not address this, it is easy to access via
- inline assembler in the GNU C and Borland compilers. As an example
- for all you Wintel fans out there (the largest audience for those
- 4 processors), I use a swap() function a lot (to convert to a reasonable
- byte order :-):
-
- #define swap(x) (_AX = (x),__emit__(0x86,0xe0),(short)_AX)
-
- generates an optimal xchg instruction. If you want to handle nested
- expressions involving swap(), then a more general version is
-
- inline short swap(short x) {
- _ax = x;
- asm xchg ah,al
- return _ax;
- }
- --
- Stuart D. Gathman <stuart@bmsi.com> / <..!uunet!bms88!stuart>
- Business Management Systems Inc.
- Phone: 703 591-0911 Fax: 703 591-6154
- "Microsoft is the QWERTY of Operating Systems" - SDG
-